package com.liuqi.openai.tool.webhook;

import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * WebHook 工具调用信息描述
 *
 * @author liuqi
 * @date 2025/7/20
 **/
@Getter
@Setter
@ToString
@AllArgsConstructor
@Builder
public class WebHook {

    private final AtomicInteger atomicInteger = new AtomicInteger();

    /**
     * webhook 服务地址列表
     */
    private List<String> servers;

    /**
     *  webhook 请求头
     */
    private Map<String, String> headers;

    /**
     * content-type
     */
    private String contentType;

    /**
     * webhook url
     */
    private String path;

    /**
     * 服务地址列表中轮询取一个地址
     *
     * @return
     */
    public String server() {
        if (servers.size() == 1) {
            return servers.get(0);
        } else {
            int i = atomicInteger.getAndIncrement();
            return servers.get(i % servers.size());
        }
    }

}
